/**
 * 定时任务详情对话框（可用于添加和修改对话框）
 */
var ScheduleAddDlg = {
    data: {
        beanName: "",
        methodName: "",
        params: "",
        cronExpression: "",
        status: "",
        remark: ""
    }
};

/**
 * 关闭此对话框
 */
ScheduleAddDlg.close = function () {
    parent.layer.close(window.parent.Schedule.layerIndex);
};

/**
 * 验证表单
 */
ScheduleAddDlg.validateForm = function () {

    var data = ScheduleAddDlg.data;

    if (!data.beanName) {
        return "bean名称不能为空";
    }
    if (!data.methodName) {
        return "方法名称不能为空";
    }
    if (!data.cronExpression) {
        return "cron表达式不能为空";
    }
    return true;
};



/**
 * 提交添加任务
 */
ScheduleAddDlg.addSubmit = function() {
    var ajax = new $ax(Feng.ctxPath + "/scheduleJobMgr/add", function(data){
        parent.Feng.success("添加成功!");
        window.parent.Schedule.table.refresh();
        ScheduleAddDlg.close();
    },function(data){
        parent.Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.data);
    ajax.start();
}

$(function() {
    ScheduleAddDlg.app = new Vue({
        el: '#schelduleForm',
        data: ScheduleAddDlg.data,
        methods: {
            submitForm: function (e) {
                e.preventDefault();
            },
            ensure: function () {
                var result = ScheduleAddDlg.validateForm();
                if (result === true) {
                    ScheduleAddDlg.addSubmit();
                } else {
                    Feng.alert(result);
                }
            },
            close: function () {
                ScheduleAddDlg.close();
            }
        }
    });
});
